package com.springboot.autoconfigure.oss.service;

import cn.hutool.core.util.StrUtil;
import com.springboot.autoconfigure.oss.config.OssConfigPropertis;
import com.springboot.autoconfigure.oss.config.PublicMetaConfig;
import org.springframework.stereotype.Component;

import java.io.File;

@Component
public abstract class AbstractFileGetFileName {

    private OssConfigPropertis ossConfigPropertis;


    public String getUUIDFileNameByTypeFile(File file){
        StringBuilder strBuilder = new StringBuilder();
        if (!StrUtil.isBlank(ossConfigPropertis.getFolderPathName())){
            strBuilder.append(ossConfigPropertis.getFolderPathName());
            strBuilder.append(PublicMetaConfig.FILEPATH_SPLITMARK);
        }
        if (!StrUtil.isBlank(ossConfigPropertis.getFilePrefix())){
            strBuilder.append(ossConfigPropertis.getFilePrefix());
            // 文件名分割符
            strBuilder.append(ossConfigPropertis.getFilePathSplit());
        }
        String fileName= cn.hutool.core.lang.UUID.randomUUID().toString();
        strBuilder.append(fileName);
        strBuilder.append(file.getName());
        String fileKey=strBuilder.toString();
        return fileKey;
    }


    public String getUUIDFileNameByTypeFile(File file,OssConfigPropertis ossConfigPropertis){
        StringBuilder strBuilder = new StringBuilder();
        if (!StrUtil.isBlank(ossConfigPropertis.getFolderPathName())){
            strBuilder.append(ossConfigPropertis.getFolderPathName());
            strBuilder.append(PublicMetaConfig.FILEPATH_SPLITMARK);
        }
        if (!StrUtil.isBlank(ossConfigPropertis.getFilePrefix())){
            strBuilder.append(ossConfigPropertis.getFilePrefix());
            // 文件名分割符
            strBuilder.append(ossConfigPropertis.getFilePathSplit());
        }
        String fileName= cn.hutool.core.lang.UUID.randomUUID().toString();
        strBuilder.append(fileName);
        strBuilder.append(file.getName());
        String fileKey=strBuilder.toString();
        return fileKey;
    }


    public String getUUIDFileNameByTypeFile(File file,OssConfigPropertis ossConfigPropertis,String pathSplit){
        StringBuilder strBuilder = new StringBuilder();
        if (!StrUtil.isBlank(ossConfigPropertis.getFolderPathName())){
            strBuilder.append(ossConfigPropertis.getFolderPathName());
            strBuilder.append(pathSplit);
        }
        if (!StrUtil.isBlank(ossConfigPropertis.getFilePrefix())){
            strBuilder.append(ossConfigPropertis.getFilePrefix());
            // 文件名分割符
            strBuilder.append(ossConfigPropertis.getFilePathSplit());
        }
        String fileName= cn.hutool.core.lang.UUID.randomUUID().toString();
        strBuilder.append(fileName);
        strBuilder.append(file.getName());
        String fileKey=strBuilder.toString();
        return fileKey;
    }
}
